<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.zsh.pojo.Student" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: ZSH
  Date: 2022/1/7
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%--
    c:set    往域中保存数据
    scope: 表示与（4种）
    var： 表示键
    value： 表示值
--%>
    <c:set scope="request" var="abc" value="123" />
    ${requestScope.get("abc")}

<%--
    c:if  作if判断
    test: 判断条件（EL表达式）
--%>
<hr>
    <c:if test="${12 == 12}" >
        <h1>12 = 12</h1>
    </c:if>
<hr>
<%--
    c:choose c:when c:otherwise
    多路判断，跟switch 。。。 case 。。。default非常接近
--%>
    <%
        request.setAttribute("height",178);
    %>

    <c:choose>
        <c:when test="${requestScope.height > 190}">
            <h1>巨人</h1>
        </c:when>
        <c:when test="${requestScope.height > 180}">
            <h1>还行</h1>
        </c:when>
        <c:otherwise>
            <h1>一般</h1>
        </c:otherwise>
    </c:choose>

<%--
    c:foreach 遍历循环
    begin : 开始
    end：结束
    var：遍历的变量
--%>
<hr>
    <c:forEach begin="1" end="10" var="i">
        ${i}
    </c:forEach>
<hr>
<%--
    变量对象数组
--%>

    <%
        request.setAttribute("arr",new String[]{"1321321","213123","342314"});
    %>

    <c:forEach items="${requestScope.get('arr')}" var="item">
        ${item}
    </c:forEach>

<%--
    遍历map
--%>
    <%
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("1","1");
        map.put("2","2");
        map.put("3","3");

        request.setAttribute("map",map);
    %>

    <c:forEach items="${requestScope.get('map')}" var="entry">
        <h1>${entry}</h1>
    </c:forEach>

<%--
    遍历List，list内放Student类
--%>

    <%
        List<Student> studentList = new ArrayList<Student>();

        for (int i = 0; i < 10; i++) {
            studentList.add(new Student(i+1,"username" + i,i+10));
        }
        request.setAttribute("studentList",studentList);

    %>
<hr>
<table border="1">
    <tr>
        <td>编号</td>
        <td>用户名</td>
        <td>年龄</td>
    </tr>

    <c:forEach items="${requestScope.studentList}" var="item">
        <tr>
            <td>${item.id}</td>
            <td>${item.username}</td>
            <td>${item.age}</td>
        </tr>
    </c:forEach>
</table>
</body>
</html>
